import { createI18n } from 'vue-i18n'
import zhCN from './zh-CN'
import en from './en'

// 定义支持的语言类型
export type Locale = 'zh-CN' | 'en'

// 支持的语言列表
export const availableLocales = [
  { code: 'zh-CN' as Locale, name: '中文' },
  { code: 'en' as Locale, name: 'English' }
]

// 创建i18n实例
export const i18n = createI18n({
  legacy: false,
  locale: (localStorage.getItem('locale') || 'zh-CN') as Locale,
  fallbackLocale: 'en',
  messages: {
    'zh-CN': zhCN,
    'en': en
  }
})

// 切换语言的方法
export function setLocale(locale: Locale) {
  i18n.global.locale.value = locale
  localStorage.setItem('locale', locale)
  
  // 同时更新Element Plus的语言
  document.documentElement.lang = locale
}

export default i18n 